package com.dong.sortingAlgorithm;

import java.util.Arrays;

public class Test {
    public static void main(String[] args) {
        int[] arr = {5,2,6,8,3,9,1,7,4,8,10};
        quick_sort2(arr,0,arr.length-1);
        System.out.println(Arrays.toString(arr));
    }

    public static void quick_sort2(int[] s,int l,int r){
        if (l<r){
            int i =l;
            int j = r;
            int x = s[l]; //基准数
            while (i<j){
                while (i<j && s[j]>=x){
                    j--;
                }
                if (i<j){
                    s[i++] = s[j];
                }

                while (i<j && s[i]<x){
                    i++;
                }
                if (i<j){
                    s[j--] = s[i];
                }
            }
            s[i] = x;
            quick_sort2(s, l, i - 1); // 递归调用
            quick_sort2(s, i + 1, r);

        }
    }

}
